package com.example.demo.component;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Aspect  //这是一个切面
@Component // 随着框架的启动而启动
public class UserAspect {

    // 定义切点 AspectJ 表达式语法
    @Pointcut("execution(* com.example.demo.controller.UserController.*(..))")
    public void pointcut() {

    }

    @Before("pointcut()")
    public void beforeAdvice() {
        System.out.println("执行了前置通知！");
    }
    @After("pointcut()")
    public void afterAdvice() {
        System.out.println("执行了后置通知！");
    }

    @Around("pointcut()")
    public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
        Object object = null;
        System.out.println("进入了环绕通知的");
        //执行目标方法
        object = joinPoint.proceed();

        System.out.println("退出环绕通知！");
        return object;
    }
}
